﻿<Window x:Class="LockCrypt.WinAddAccount"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:LockCrypt"
    xmlns:lex="http://schemas.root-project.org/xaml/presentation"
    xmlns:l49="clr-namespace:Lime49;assembly=Lime49"
    xmlns:l49ui="clr-namespace:Lime49.UI;assembly=Lime49"
    xmlns:conv="clr-namespace:LockCrypt.Converters"
    xmlns:autotype="clr-namespace:LockCrypt.AutoType"
    Title="{lex:LocText LockCrypt.Core:Strings:AddAccount}" Style="{StaticResource {x:Type Window}}" Icon="/LockCrypt;component/Resources/LockCrypt.ico"
    MinHeight="250" MinWidth="100" Width="400" SizeToContent="Height"
    WindowStartupLocation="CenterOwner" x:Name="root" Loaded="Window_Loaded" Closing="Window_Closing"
    l49:WindowService.EscapeClosesWindow="True">
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Close" Executed="CloseWindow" />
        <CommandBinding Command="ApplicationCommands.Help" Executed="ShowHelp" />
        <CommandBinding Command="ApplicationCommands.New" Executed="OpenIconsDirectory" />
        <CommandBinding Command="ApplicationCommands.Save" Executed="Save" />
        <CommandBinding Command="loc:AutoTypeRecorder.Record" Executed="Record" CanExecute="CanExecuteRecord"  />
        <CommandBinding Command="loc:LockCryptCommands.InsertDelay" Executed="InsertDelay" CanExecute="CanInsertAutoTypeMeta"  />
        <CommandBinding Command="loc:LockCryptCommands.InsertField" Executed="InsertField" CanExecute="CanInsertAutoTypeMeta"/>
    </Window.CommandBindings>
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <conv:FieldToMenuItemConverter x:Key="FieldToMenuItemConverter"/>
    </Window.Resources>
    <DockPanel Margin="6" LastChildFill="True">
        <Grid DockPanel.Dock="Bottom">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <l49ui:ImageButton Grid.Column="0" MinWidth="70" Command="ApplicationCommands.Help" Image="pack://application:,,,/Resources/Images/question_16.png" ImageLocation="Left" Text="{lex:LocText LockCrypt.Core:Strings:Help}" ToolTip="{lex:LocText LockCrypt.Core:Strings:HelpContents}" Margin="0,2,2,2" />
            <Button Grid.Column="2" MinWidth="70" IsDefault="True" Command="ApplicationCommands.Save" Content="{lex:LocText LockCrypt.Core:Strings:Save}" />
            <Button Grid.Column="3" MinWidth="70" IsCancel="True" Command="ApplicationCommands.Close" Content="{lex:LocText LockCrypt.Core:Strings:Cancel}"/>
        </Grid>
        <TabControl x:Name="tbcTabs" DockPanel.Dock="Top" SelectionChanged="tbcTabs_SelectionChanged">
            <TabItem x:Name="tabGeneral" Header="{lex:LocText LockCrypt.Core:Strings:General}" Grid.IsSharedSizeScope="True">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" SharedSizeGroup="labels" />
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:Name}"/>
                    <TextBox Grid.Row="0" Grid.Column="1" x:Name="txtName" TabIndex="1" Text="{Binding Account.Name,ElementName=root,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />

                    <Label Grid.Row="1" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:Group}"/>
                    <ComboBox Grid.Row="1" Grid.Column="1" x:Name="cboGroup" TabIndex="2" SelectedValuePath="ID" DisplayMemberPath="Name" SelectedValue="{Binding Account.ParentID,ElementName=root,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
                    
                    <Label Grid.Row="2" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:Template}"/>
                    <ComboBox Grid.Row="2" Grid.Column="1" x:Name="cboTemplate" TabIndex="2" DisplayMemberPath="Name" SelectedValuePath="ID" SelectedItem="{Binding Account.Template,ElementName=root,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" SelectionChanged="cboTemplate_SelectionChanged"/>
                    
                    <loc:FieldEditor Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" x:Name="fieldEditor" />
                </Grid>
            </TabItem>
            <TabItem x:Name="tabNotes" Header="{lex:LocText LockCrypt.Core:Strings:Notes}" Visibility="{Binding Account.Template.ShowNotes,ElementName=root,Mode=OneWay,Converter={StaticResource BooleanToVisibilityConverter},FallbackValue='Visible'}">
                <TextBox x:Name="txtNotes" TabIndex="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="{Binding Account.Notes,ElementName=root,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                         HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" AcceptsReturn="True"/>
            </TabItem>
            <TabItem x:Name="tabAutoType" Header="{lex:LocText LockCrypt.Core:Strings:AutoType}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" SharedSizeGroup="labels" />
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Label Grid.Row="0" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:TargetWindow}"/>
                    <autotype:WindowChooser Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" SelectedWindow="{Binding Account.AutoTypeConfig.TargetWindow,ElementName=root,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>

                    <Label Grid.Row="1" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:Configuration}"/>
                    <TextBox Grid.Row="1" Grid.Column="1" x:Name="txtAutoTypeConfig" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" TextWrapping="Wrap" 
                             Text="{Binding Account.AutoTypeConfig.CommandString,ElementName=root,Mode=OneWay}"/>
                    
                    <Grid Grid.Row="1" Grid.Column="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <l49ui:ImageButton Grid.Row="0" HorizontalAlignment="Stretch" Command="loc:AutoTypeRecorder.Record" Image="pack://application:,,,/Resources/Images/record_16.png" CommandParameter="true" 
                                         ImageLocation="Top" Text="{lex:LocText LockCrypt.Core:Strings:RecordAction}" Margin="2" Padding="1" />
                        <l49ui:ImageButton Grid.Row="1" HorizontalAlignment="Stretch" Command="loc:AutoTypeRecorder.Record" Image="pack://application:,,,/Resources/Images/stop_16.png" CommandParameter="false" 
                                         ImageLocation="Top" Text="{lex:LocText LockCrypt.Core:Strings:StopRecording}" Margin="2" Padding="1" />
                        <Button Grid.Row="2" HorizontalAlignment="Stretch" Command="loc:LockCryptCommands.InsertDelay" Content="{lex:LocText LockCrypt.Core:Strings:InsertDelay}" Margin="2" Padding="1"/>
                        <l49ui:MenuButton Grid.Row="3" x:Name="btnInsertField" HorizontalAlignment="Stretch" Command="loc:LockCryptCommands.InsertField" Content="{lex:LocText LockCrypt.Core:Strings:InsertField}" Margin="1" Padding="1"
                                        Menu="{Binding Account.Fields,ElementName=root,Mode=OneWay,Converter={StaticResource FieldToMenuItemConverter}}" AlwaysShowBorder="True" ShowArrow="False" MenuLocation="Right"/>
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem x:Name="tabIcon" Header="{lex:LocText LockCrypt.Core:Strings:Icon}">
                <StackPanel HorizontalAlignment="Stretch">
                    <ListBox x:Name="lstIcon" Style="{StaticResource LargeIconList}" SelectedValue="{Binding Account.Icon,ElementName=root,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ItemStringFormat="32" SelectedValuePath="Key" >
                        <ListBox.Resources>
                            <Style TargetType="{x:Type ListBoxItem}">
                                <Setter Property="Width" Value="40"/>
                                <Setter Property="Height" Value="40"/>
                                <Setter Property="Tag" Value="32"/>
                            </Style>
                        </ListBox.Resources>
                    </ListBox>
                    <l49ui:ImageButton HorizontalAlignment="Right" Command="ApplicationCommands.New" Image="pack://application:,,,/Resources/Images/add_16.png" 
                                     ImageLocation="Left" Text="{lex:LocText LockCrypt.Core:Strings:AddMore}" Margin="2"/>
                </StackPanel>
            </TabItem>
        </TabControl>
    </DockPanel>
</Window>
